package com.itheima.myfile.test1;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test1 {
    public static void main(String[] args) throws IOException {
        //创建文件
//        File file = new File("day12_file&IOstream\\a.txt");//自动生成文件
//        boolean newFile = file.createNewFile();
//        System.out.println(newFile);
//        file.delete();
        //先将文件内容写入本地当中
        FileOutputStream fos = new FileOutputStream("day12_file&IOstream\\a.txt");
//        fos.write(97);
//        fos.write(98);
//        fos.write(99);
//        fos.write(100);
        //将指定字节数组写入
       // byte[] bytes = {97,98,99,100,101};

        byte[] bytes = "abcdef".getBytes();//将指定字符串变为字节码
        //写数据,从指定索引到某处
        fos.write(bytes,0,bytes.length);
        //关闭流
        fos.close();
        //字节流写入数据:是将文件写入本地
        FileInputStream fis = new FileInputStream("day12_file&IOstream\\a.txt");
        //对数据用read
        int b;
        byte[] bytes1 = new byte[1024];
        //循环读取
        while((b=fis.read())!=-1){
            System.out.println(System.lineSeparator());
            System.out.print((char) b);
        }
        fis.close();

    }
}
